﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER [dbo].[trg_patientHistory]
   ON  [dbo].[Patients]
   AFTER update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	insert into PatientsHistory
	(
		[patientID]
      ,[patientEntID]
      ,[patientLocationID]
      ,[patientMemberDate]
      ,[patientFirstName]
      ,[patientLastName]
      ,[patientEmailList]
      ,[patientEmailAddress]
      ,[patientCreateDate]
      ,[patientPrescriptionNumber]
      ,[patientDatePrescriptionExpiration]
      ,[patientAddress]
      ,[patientAddress2]
      ,[patientCity]
      ,[patientState]
      ,[patientZip]
      ,[patientPhoneCell]
      ,[patientPhoneHome]
      ,[patientPhoneOther]
      ,[patientAllowSMS]
      ,[patientDatePhd]
      ,[patientDateBirth]
      ,[patientDriversLicenseNumber]
      ,[patientDriversLicenseString]
      ,[patientDriversLicenseState]
      ,[patientDoctorID]
      ,[doNotContact]
      ,lastUpdateDate
      ,lastUserID
      ,ismember
      ,patientMemberLocation
      
	)
	
	 
	
	SELECT [patientID]
      ,[patientEntID]
      ,[patientLocationID]
      ,[patientMemberDate]
      ,[patientFirstName]
      ,[patientLastName]
      ,[patientEmailList]
      ,[patientEmailAddress]
      ,[patientCreateDate]
      ,[patientPrescriptionNumber]
      ,[patientDatePrescriptionExpiration]
      ,[patientAddress]
      ,[patientAddress2]
      ,[patientCity]
      ,[patientState]
      ,[patientZip]
      ,[patientPhoneCell]
      ,[patientPhoneHome]
      ,[patientPhoneOther]
      ,[patientAllowSMS]
      ,[patientDatePhd]
      ,[patientDateBirth]
      ,[patientDriversLicenseNumber]
      ,[patientDriversLicenseString]
      ,[patientDriversLicenseState]
      ,[patientDoctorID]
      ,[doNotContact]
      ,getdate()
      ,lastUserID
      ,ismember
      ,patientMemberLocation
      from deleted
	
	
END